package com.mexico.inloancash.dialog;


import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;

import androidx.annotation.NonNull;

import com.mexico.inloancash.R;
import com.mexico.inloancash.utils.MyPreferencesManager;

public class India_User_Agreement_CommonDialog extends Dialog {
    private Button dialog_bottom;
    private WebView web;;
     public India_User_Agreement_CommonDialog(@NonNull Context context) {
        super(context,R.style.time_dialog_new);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.india_activity_agreement_view_layout_dialog);
        Window win = getWindow();
        win.setGravity(Gravity.CENTER);
        WindowManager.LayoutParams lp = win.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.MATCH_PARENT;
        win.setAttributes(lp);
        setCanceledOnTouchOutside(false);
        dialog_bottom = findViewById(R.id.dialog_bottom);
        dialog_bottom.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MyPreferencesManager.putIsShow(true);
                dismiss();
            }
        });

        web=findViewById(R.id.web);
        web.setHorizontalScrollBarEnabled(false);//水平不显示
        web.setVerticalScrollBarEnabled(false); //垂直不显示
        setWebView();
        web.setWebChromeClient(new WebChromeClient());
       // web.loadUrl("http://adminmxwa.cmd2019.cn/appapi/login/contract");
        web.loadUrl("file:///android_asset/contract.html");
        //覆盖WebView默认使用第三方或系统默认浏览器打开网页的行为，使网页用WebView打开
        web.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // TODO Auto-generated method stub
                //返回值是true的时候控制去WebView打开，为false调用系统浏览器或第三方浏览器
                view.loadUrl(url);
                return true;
            }
        });
    }

    public void setWebView() {
        WebSettings webSettings = web.getSettings();
        webSettings.setJavaScriptEnabled(true);
        // User settings

        webSettings.setJavaScriptEnabled(true);
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webSettings.setUseWideViewPort(true);//关键点

        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);

        webSettings.setDisplayZoomControls(false);
        webSettings.setJavaScriptEnabled(true); // 设置支持javascript脚本
        webSettings.setAllowFileAccess(true); // 允许访问文件
        webSettings.setBuiltInZoomControls(true); // 设置显示缩放按钮
        webSettings.setSupportZoom(true); // 支持缩放

    }
}
